var t = getApp(), a = require("../../0BACB9C3A71FB5DF6DCAD1C4BE4CA4D1.js"), n = require("../../A4730AC3A71FB5DFC21562C4223CA4D1.js");

Page({
    data: {
        statusBarHeight: t.globalData.statusBarHeight,
        titleBarHeight: t.globalData.titleBarHeight,
        isLogin: !1,
        isLogining: !1,
        user: {},
        navType: "",
        navUrl: {
            order: "/pages/order/list",
            coupon: "/pages/coupon/index",
            collect: "/pages/collect/index",
            address: "/pages/address/index"
        },
        isLoadingCouponCount: !1,
        isLoadingOrderCount: !1,
        couponCount: 0,
        orderCount: 0
    },
    onShow: function() {
        var n = this;
        null !== a._cb && (this.setData({
            isLogining: !1
        }), a._cb = null);
        var o = t.globalData.isLogin;
        this.setData({
            isLogin: o,
            user: t.globalData.user
        }, function() {
            o && (n.getCouponCount(), n.getOrderCount());
        });
    },
    handleTap: function(n) {
        var o = this, i = n.currentTarget.dataset.type;
        if (t.globalData.isLogin) this.handleNav(i); else {
            if (this.setData({
                navType: i
            }), this.data.isLogining) return;
            this.setData({
                isLogining: !0
            }, function() {
                a.login(function(t) {
                    o.setData({
                        isLogining: !1
                    }), 1001 === t && o.setData({
                        isLogin: !0
                    }, function() {
                        o.getCouponCount(), o.getOrderCount(), o.handleNav(o.data.navType);
                    });
                });
            });
        }
    },
    handleNav: function(t) {
        "login" !== t && wx.navigateTo({
            url: this.data.navUrl[t]
        });
    },
    getCouponCount: function() {
        var n = this;
        t.globalData.isLogin && !this.data.isLoadingCouponCount && (this.setData({
            isLoadingCouponCount: !0
        }), a.getCouponCount(function(t) {
            n.setData({
                isLoadingCouponCount: !1
            }), 1001 === t.data.code && n.setData({
                couponCount: 1 * t.data.response.data.count
            });
        }, function() {
            n.setData({
                isLoadingCouponCount: !1
            });
        }));
    },
    getOrderCount: function() {
        var a = this;
        t.globalData.isLogin && !this.data.isLoadingOrderCount && (this.setData({
            isLoadingOrderCount: !0
        }), n.get("/v2/order/product/effective").then(function(t) {
            a.setData({
                isLoadingOrderCount: !1
            }), 1001 === t.data.code && a.setData({
                orderCount: t.data.response.data.num || 0
            });
        }).catch(function() {
            a.setData({
                isLoadingOrderCount: !1
            });
        }));
    }
});